<?php
/**
 * Created by PhpStorm.
 * User: zhangxilu
 * Date: 2017/12/19
 * Time: 下午11:12
 */

namespace backend\controllers;

use Yii;
use backend\models\CounterFormModel;
use common\models\CounterDataModel;

class SystemController extends BaseController
{

    public function actionIndex()
    {
        $model =$this->findCounterModel();

        $post = Yii::$app->request->post();
        if(!empty($post['CounterDataModel']['total_save'])) {
            $model->total_save=intval($post['CounterDataModel']['total_save']);
            $model->total_user=intval($post['CounterDataModel']['total_user']);
            $model->save();
        }

        return $this->render('counter', [
            'model' => $model,
        ]);
    }


    protected function findCounterModel()
    {
        $model = CounterDataModel::find()->one();
        if ($model !== null) {
            return $model;
        }
    }

}